#pragma once
#pragma warning( disable : 4290 )

#include "Definitions.h"
#include "SenetBoardDraft.h"
#include "SenetHeuristicsSimetric.h"
#include "SenetMove.h"
#include "SticksProbability.h"
#include "CommonAlgorithmsDefs.h"

 class Star1
 {
 public:
	 
	 //C'tor
	// Expectimax(SenetHeuristics& heuristic);

	 //initialize the algorithm
	 void Init(const SenetPlayerExt* owner , int gameStickNum);
	 
	 //Assignment operator
	 //Expectimax& Expectimax::operator=(const Expectimax& e);

	 //return expectimax score for the given board
	 SenetMove scoreExpectimax(SenetBoardDraft& boardOrig, int depth, const GameTimer& timer ,
								bool checkTime , Definitions::PlayerColor myColor, int stickNum) throw(Exception);
	 
	//TODO: debug
	 float FinalBoardScore()
	 {
		 float res = m_FinalBoardScore;
		 return res;
	 }
	 
	 float m_FinalBoardScore;
 private:
	 SenetHeuristicsSimetric m_heuristic;
	 int m_gameStickNum;
	 SticksProbability m_probabilities;

	 //functions:
	 
	 Score chanceSearch(SenetBoardDraft& board, int depth, const GameTimer& timer, bool checkTime ,
						Definitions::PlayerColor currentPlayer, int stickNum ,  
						NodeType nodeType , NodeType nextTurn, float alpha, float beta) throw(Exception);
	 

	 void negamax(
		Score& res ,
		SenetBoardDraft& board,
		int depth,
		const GameTimer& timer,
		bool checkTime,
		Definitions::PlayerColor currentPlayer,
		int stickNum /* the number of sticks that current player got */,
		NodeType nodeType,
		float alpha,
		float beta);
	 
	 void expectimax(Score& res, SenetBoardDraft &board, int depth, const GameTimer& timer, bool checkTime , 
						Definitions::PlayerColor nextPlayer, NodeType nodeType, float alpha, float beta) throw (Exception);

	 // TODO: calculate this in advanced, and save it in the cache
	inline float getProbabilityLeft(int finishedSuccessors /* index i */)
	{
		float total = 0.0f;
		for (int i = finishedSuccessors + 1; i <= m_gameStickNum; ++i)
		{
			total += m_probabilities.getProbability(i);
		}
		return total;
	}

 };